Page({
  data: {
    list: [],
  },
  async init() {
    try {
      wx.request({
        url: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/category.json',  // 外部JSON文件地址
        method: 'GET',
        header: {
          'content-type': 'application/json'  // 指定返回数据类型为JSON
        },
        success: (res) => {
          if (res.statusCode === 200) {
            // console.log('日记分类数据:', res.data);
            // 将获取到的数据存储到页面的data中
            this.setData({
              list: res.data
            });
          } else {
            console.error('获取JSON失败，状态码:', res.statusCode);
          }
        },
        fail: (err) => {
          console.error('请求失败:', err);
        }
      });


    } catch (error) {
      console.error('err:', error);
    }
  },

  onShareAppMessage: function () {
    return {
      title: '枫味日记',
      path: '/pages/home/home',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },
  onShareTimeline: function () {
    return {
      title: '枫味日记',
      imageUrl: 'https://gitee.com/chen-feng1111/mycookbook/raw/master/images/category/share.jpg'
    };
  },

  onShow() {
    this.getTabBar().init();
  },

  onChange(event) {

    const selectedCategory = event.detail;
    const groupId = selectedCategory.item.groupId;

    wx.navigateTo({
      url: `/pages/goods/list/index?groupId=${groupId}`,
    });

  },
  onLoad() {
    this.init(true);
  },
});
